#include "bitree.h"

/*
    i
  u   u
 c # # c
# #   # #

input format:iuc###u#c##
*/
void test_recursion_algorithm()
{
    BiTree tree;
    initTree(tree);
    cout<<"Please enter preorder data in a signle line :"<<endl;
    createTree(tree);
    cout<<"getTreeDepth:"<<getTreeDepth(tree)<<endl;

    cout<<"preOrderTraverse:"<<endl;
    preOrderTraverse(tree);
    cout<<endl;

    cout<<"inOrderTraverse:"<<endl;
    inOrderTraverse(tree);
    cout<<endl;

    cout<<"postOrderTraverse:"<<endl;
    postOrderTraverse(tree);
    cout<<endl;
}

void test_nonrecursion_algorithm(){
    BiTree tree;
    initTree(tree);
    cout<<"Please enter preorder data in a signle line :"<<endl;
    createTree(tree);
    preOrderTraverse(tree);
    cout<<"getTreeDepth:"<<getTreeDepth(tree)<<endl;

    Stack stack;
    stack.init();
    BiTreeNode *node = tree;
    while(node != NULL || !stack.isEmpty()){
        if(node != NULL){
            stack.push(*node);
            node= node->lchild;
            stack.display("push");
        }else{
            stack.pop(*node);
            cout<<"data:"<<stack.getTop()->data<<endl;
            stack.display("pop");
            node = stack.s.top;
        }
    }
}

void test_stack()
{
    BiTreeNode b1;
    BiTreeNode b2;
    BiTreeNode b3;
    BiTreeNode temp;

    b1.data = '3';
    b2.data = '4';
    b3.data = '5';

    Stack stack;
    stack.init();
    stack.push(b1);
    stack.push(b2);
    stack.push(b3);

    stack.display("test");

    stack.pop(temp);
    cout<<"data="<<temp.data<<endl;
    stack.pop(temp);
    cout<<"data="<<temp.data<<endl;
    stack.pop(temp);
    cout<<"data="<<temp.data<<endl;
}

int main()
{
    test_recursion_algorithm();
//    test_nonrecursion_algorithm();
//    test_stack();
    return 0;
}


